home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DBPCXL15.ARJ / DEMOS.ARJ / PCXHDR.C next >
C/C++ Source or Header  |  1992-01-26  |  2KB  |  61 lines

  1. /*  pcx.c  : a .PCX file viewer */
  2.  
  3. #include <stdio.h>
  4. #include "pcxlib.h"
  5.  
  6. void PCXprint_header(PCXH *h);
  7.  
  8. void do_help(void)
  9. {
  10.   printf("pcxhdr will print the value in the pcx header"
  11.          " block of file specified.\n");
  12.  
  13. }
  14.  
  15. void main(int argc, char *argv[])
  16. {
  17.     PCXH  pcx;
  18.     FILE *fp;
  19.     int i;
  20.  
  21.     if (argc < 2) { do_help(); exit(1); }
  22.     if (!(fp=fopen(argv[1],"rb"))) {
  23.        printf("Error opening \"%s\".\n", argv[1]);
  24.        exit(2);
  25.     }
  26.     if ( fread(&pcx,sizeof(PCXH),1,fp) < 1 ) {
  27.        printf("Error reading header from \"%s\".\n", argv[1]);
  28.        exit(3);
  29.     }
  30.     PCXprint_header(&pcx);
  31. }
  32.  
  33. /****************************************************************************
  34. //    PCXprint_header
  35. ****************************************************************************/
  36. void PCXprint_header(PCXH *pcx)
  37. {
  38.     int i;
  39.     printf("Magic code    : %02x\n", pcx->MagicId);
  40.     printf("Version       : %02x\n", pcx->Version);
  41.     printf("Encoding      : %02x\n", pcx->Encoding);
  42.     printf("Bits per Pixel: %02x\n", pcx->BitsPixel);
  43.     printf("X min         : %u\n",   pcx->Xmin);
  44.     printf("Y min         : %u\n",   pcx->Ymin);
  45.     printf("X max         : %u\n",   pcx->Xmax);
  46.     printf("Y max         : %u\n",   pcx->Ymax);
  47.     printf("H res         : %u\n",   pcx->Hres);
  48.     printf("V res         : %u\n",   pcx->Vres);
  49.     if (pcx->BitsPixel < 5 ) {
  50.     for (i=0; i<16; i++)
  51.         printf("Palette #%02u   : r %02x g %02x b %02x\n", i,
  52.            pcx->Palette[i].r, pcx->Palette[i].g, pcx->Palette[i].b);
  53.     }
  54.     printf("Planes        : %u\n",   pcx->Planes);
  55.     printf("Bytes per Line: %u\n",   pcx->bytesline);
  56.     printf("Palette Info  : %04x\n", pcx->PaletteInfo);
  57.     return;
  58. }
  59.  
  60.  
  61.